package com.example.Utility;/**
 * 财哥
 * <p>
 * 2023.4.13
 * Mybitas-puls
 */

import reactor.util.annotation.Nullable;

import java.util.Collection;
import java.util.Map;

/**
 * @author Super
 * @version 1.0
 * @description: TODO
 * @date 2023.4.13 12:27
 */
public class objIsNull {

    /**
     * 判断对象是否为空
     *
     * @param obj 对象
     * @return true：对象为空；false：对象非空
     */
    public static boolean isNull(@Nullable Object obj) {
        if (obj == null) {
            return true;
        }
        if (obj instanceof CharSequence) {
            return ((CharSequence) obj).length() == 0;
        }
        if (obj instanceof Collection) {
            return ((Collection) obj).isEmpty();
        }
        if (obj instanceof Map) {
            return ((Map) obj).isEmpty();
        }
        if (obj instanceof Object[]) {
            Object[] object = (Object[]) obj;
            if (object.length == 0) {
                return true;
            }
            boolean empty = true;
            for (int i = 0; i < object.length; i++) {
                if (!isNull(object[i])) {
                    empty = false;
                    break;
                }

            }
            return empty;
        }
        if (obj instanceof boolean[]) {
            return ((boolean[]) obj).length == 0;
        }
        if (obj instanceof byte[]) {
            return ((byte[]) obj).length == 0;
        }
        if (obj instanceof char[]) {
            return ((char[]) obj).length == 0;
        }
        if (obj instanceof double[]) {
            return ((double[]) obj).length == 0;
        }
        if (obj instanceof float[]) {
            return ((float[]) obj).length == 0;
        }
        if (obj instanceof int[]) {
            return ((int[]) obj).length == 0;
        }
        if (obj instanceof long[]) {
            return ((long[]) obj).length == 0;
        }
        if (obj instanceof short[]) {
            return ((short[]) obj).length == 0;
        }
        return false;
    }

    /**
     * 判断对象是否非空
     *
     * @param obj 对象
     * @return true：对象非空；false：对象为空
     */
    public static boolean isNotEmpty(Object obj) {
        return !isNull(obj);
    }

}
